//
//  LSZSpecialPackaging.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/27.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZSpecialPackaging.h"

@implementation LSZSpecialPackaging
+(CGFloat)getHeightOfText :(CGFloat)width height:(CGFloat)height font:(CGFloat)font :(NSString * )text
{
    //1.限制大小 2.绘制选项 3.属性（字号大小） 4.一般传nil
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:font]} context:nil];
    CGFloat whatHeight = ceilf(rect.size.height);
    return whatHeight+20;
}
#pragma mark - 获取自适应宽度
+(CGFloat)getsTheAdaptiveWidth:(UILabel *)label sizeMaxWidth:(CGFloat)sizeMaxWidth
{
    CGSize size = CGSizeMake(sizeMaxWidth, MAXFLOAT);//设置高度宽度的最大限度
    CGRect rect = [label.text boundingRectWithSize:size options:NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : label.font} context:nil];
    return rect.size.width;
}
//+(CGFloat)caculateWidthOfText:(CGFloat)width height:(CGFloat)height font:(CGFloat)font :(NSString *)text
//{
//
//}
#pragma mark - 下面的评论框
+(void)initWithAppraise:(UIView *)view :(strPinglLun)block
{
    UIView * lowView = [[UIView alloc]init];
    lowView.frame = CGRectMake(0,ScreenHeight-60-HOME_INDICATOR_HEIGHT, ScreenWidth, 60);
    lowView.backgroundColor = [UIColor whiteColor];
    [view addSubview:lowView];
    
    UITextView * textView = [[UITextView alloc]init];
    textView.frame = CGRectMake(20, 10, ScreenWidth-40-60, lowView.frame.size.height-20);
    //    textView. = @"点击此处说两句...";
    //    textView.scrollEnabled = NO;
    textView.scrollsToTop = NO;
    textView.font = [UIFont systemFontOfSize:14];
    textView.backgroundColor = RGBColor(243, 243, 243);
    //当textview的字符串为0时发送（rerurn）键无效
    textView.enablesReturnKeyAutomatically = YES;
    textView.keyboardType = UIKeyboardTypeDefault;
    //    //键盘return样式变成发送
    textView.returnKeyType = UIReturnKeySend;
    [lowView addSubview:textView];
    
    UIButton * butSend = [[UIButton alloc]init];
    butSend.frame = CGRectMake(CGRectGetMaxX(textView.frame)+10,15,60, lowView.frame.size.height-30);
    butSend.backgroundColor = RGBColor(243, 243, 243);
    [butSend.layer setMasksToBounds:YES];
    [butSend setTitle:@"发送" forState:UIControlStateNormal];
    [butSend setTitleColor:lightColor forState:UIControlStateNormal];
    butSend.titleLabel.font = FONT_(14);
    [butSend.layer setCornerRadius:butSend.frame.size.height/2];
    [lowView addSubview:butSend];
    block(lowView,textView,butSend);
    
}
#pragma mark - 转json
+(NSArray *)stringToJSON:(NSString *)jsonStr {
    if (jsonStr) {
        id tmp = [NSJSONSerialization JSONObjectWithData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments | NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers error:nil];
        
        if (tmp) {
            if ([tmp isKindOfClass:[NSArray class]]) {
                
                return tmp;
                
            } else if([tmp isKindOfClass:[NSString class]]
                      || [tmp isKindOfClass:[NSDictionary class]]) {
                
                return [NSArray arrayWithObject:tmp];
                
            } else {
                return nil;
            }
        } else {
            return nil;
        }
        
    } else {
        return nil;
    }
}
@end
